home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / IDEDRVR / DTEST.C next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  9.2 KB  |  312 lines

  1. /*** dtest.c
  2.  *
  3.  *  DTEST.TTP  -- Disk/DMA test program
  4.  *    gcc {-DVERBOSE} -o dtest.ttp dtest.c -liio
  5.  *
  6.  *  910315 JWTittsler    originally a wrapper for TT DMA test program
  7.  *  910325 jwt    make the GetBPB() call only if given the -B switch
  8.  *        show only first 10 errors/cycle, unless given -E switch
  9.  *  910326 jwt    make clearing the buffers optional, setable fill value
  10.  *        -L sets limit from base record; if set then -I specifies
  11.  *          increment from one cycle to next, if I==0 then random
  12.  *          blocks
  13.  *  910404 jwt    ring bell on errors unless given the -q (quiet) switch
  14.  *  910627 jwt    -T nn  enter standby mode before writes, pause nn ticks
  15.  *        -U nn  enter standby mode before reads, pause nn ticks
  16.  *        keywait at end of Usage() help screen
  17.  */
  18.  
  19. #define VERSION "  Version of Jun 27 17:50:00 JST 1991"
  20.  
  21. #define OPTIONS "bBc:C:d:D:eEfFi:I:l:L:o:O:p:P:qQr:R:s:S:t:T:u:U:Zz"
  22. #define    RECORDSIZE    (512L)
  23. #define SLOP        (8L)    /* space between buffers (in bytes) */
  24. #define    SHOWABLEERRORS    (10L)    /* default number of errors to show per pass */
  25.  
  26. /* hardware and OS address definitions */
  27. #define    HZ200        ((volatile long *)0x000004BAL)
  28. #define    IDECOMMAND    ((volatile short *)0xFFF0001CL)
  29. #define    IDESTATUS    ((volatile short *)0xFFF0001CL)
  30.  
  31. #define    IDEBUSY        (0x80)
  32.  
  33. /* IDE commands */
  34. #define    IDESTANDBY    (0xE0)
  35. #define IDEIDLE        (0xE1)
  36.  
  37. /* BIOS Definitions */
  38. /* Bconxx() handles */
  39. #define    CONSOLE        2
  40.  
  41. /* Rwabs() flags */
  42. #define    READ        (0)
  43. #define WRITE        (1)
  44. #define    PHYSICAL    (8)
  45. #define    PHYSREAD    (READ+PHYSICAL)
  46. #define    PHYSWRITE    (WRITE+PHYSICAL)
  47.  
  48. #include <stdlib.h>
  49. #include <stdio.h>
  50. #include <osbind.h>
  51. #include <ctype.h>
  52. #include <unixlib.h>
  53. #include <string.h>
  54.  
  55. extern int opterr,optind;
  56. extern char *optarg;
  57.  
  58. long lErrors=0L;
  59. int bAllErrors=0;
  60. int bQuiet=0;
  61. int nWritePause=-1;
  62. int nReadPause=-1;
  63.  
  64. void Usage(void){
  65.     puts("DTEST -B -E -F -Z -C nnnn -D nn -I nnnn \
  66. -L nnnn -O n -P nnn -R nnnn -T nn -U nn");
  67.     puts("  where:");
  68.     puts("   -B       do getbpb() call");
  69.     puts("   -E       show all errors {first 10/cycle}");
  70.     puts("   -F       put buffer in Fast RAM");
  71.     puts("   -Q       be quiet on errors");
  72.     puts("   -Z       don't preset read buffers");
  73.     puts("   -C nnnn  record count {40}");
  74.     puts("   -D nn    TOS physical device number {0}");
  75.     puts("   -I nnnn  increment {0, random if limit specified}");
  76.     puts("   -L nnnn  limit to be added to base record number {0}");
  77.     puts("   -O n     offset from long alignment {0}");
  78.     puts("   -P nnn   read buffer preset value {0}");
  79.     puts("   -R nnnn  base starting record number {100}");
  80.     puts("   -T nnn   enter standby, pause nn sec before writes");
  81.     puts("   -U nnn   enter standby, pause nn sec before reads");
  82.     printf("\nStrike a key to continue...");  fflush(stdout);
  83.     (void)Cconin();        /* swallow up character */
  84. }
  85.  
  86. void StandbyPause(int nTickDelay){
  87. long lOldSSP;
  88. long lTimeOut;
  89.  
  90.     lOldSSP = Super(0L);    /* enter supervisor mode */
  91.  
  92.     /* make sure the drive is not busy, and clear any pending IRQ */
  93.     while(*IDESTATUS & IDEBUSY) ;
  94.  
  95.     /* issue command to immediately enter STANDBY mode */
  96.     *IDECOMMAND = IDESTANDBY;
  97.  
  98.     /* wait for BUSY to go away, and clear IRQ */
  99.     while(*IDESTATUS & IDEBUSY) ;
  100.  
  101.     if(nTickDelay > 0) {
  102.         lTimeOut = *HZ200 + nTickDelay;
  103.         while(*HZ200 < lTimeOut) ;
  104.     }
  105.  
  106.     (void)Super(lOldSSP);    /* return to user mode */
  107. }
  108.  
  109. int GetNumArg(char *string){
  110.     return(atoi(string));    /* someday this will handle hex and decimal */
  111. }                /*  yeah, sure */
  112.  
  113. char *Myalloc(long size, short type){
  114. int nTOSVersion, nTemp;
  115.     nTemp = Sversion();
  116.     nTOSVersion = (nTemp>>8) | ((nTemp&0xFF)<<8);    /* byte swap */
  117.     if (nTOSVersion >= 0x0019) return (char *)Mxalloc(size, type);
  118.     else if (type) return NULL;    /* old TOS only has one kind of RAM */
  119.     else return (char *)Malloc(size);
  120. }
  121.  
  122. void SetBuffer(unsigned char *pB, long lBufferSize, int nPass) {
  123. register int i;
  124. register unsigned char bVal;
  125.     bVal = (unsigned char) nPass;
  126.     for(i=0; i<lBufferSize; ++i){
  127.         *pB++ = bVal++;
  128.     }
  129.     memcpy(pB, "\0x11\0x22\0x33\0x44\0x55\0x66\0x77\0x88", 8);
  130. }
  131.  
  132. int CompareBuffers(register unsigned char *p1, register unsigned char *p2,
  133.     register unsigned char *p3, register long lBSize){
  134. register long i;
  135. register unsigned char c1,c2,c3;
  136. unsigned char *wbuf;
  137. long lErrorsThisCycle=0L;
  138.  
  139.     wbuf = p1;
  140.     for(i=0; i<lBSize; ++i) {
  141.         c1 = *p1++;  c2 = *p2++;  c3 = *p3++;
  142.         if((c1 != c2) || (c1 != c3)) {
  143.         ++lErrors;
  144.         ++lErrorsThisCycle;
  145.         --p1;
  146.         if((lErrorsThisCycle <= SHOWABLEERRORS)||(bAllErrors))
  147.             printf("\nError @ wbuf 0x%08X (offset 0x%06X) \
  148. Wr: %s0x%02X\033q Rd: %s0x%02X\033q 2nd Rd: %s0x%02X\033q",
  149.             (long)(p1), (long)(p1-wbuf),
  150.             ((c1==c2)||(c1==c3)) ? "\033p" : "", c1,
  151.             ((c2==c1)||(c2==c3)) ? "\033p" : "", c2,
  152.              ((c3==c1)||(c3==c2)) ? "\033p" : "", c3);
  153.         ++p1;
  154.         if(Cconis() != 0) break;
  155.         }
  156.     }
  157.     if(lErrorsThisCycle) printf("\nErrors this cycle: %ld",
  158.         lErrorsThisCycle);
  159.     return (int)(lErrorsThisCycle != 0);
  160. }
  161.  
  162. void main(int argc, const char *argv[]){
  163. int option;
  164. int nOffset=0, nDevice=0, nBaseRecord=100, nRecord=100, nCount=40;
  165. int nLimit=0, nIncrement=0;
  166. int bFastRAM=0, bDoGetBPB=0, bDoBufferFill=1;
  167. unsigned char *pBuffer,*pBuf1,*pBuf2,*pBuf3,cSeed;
  168. long lBufferSize;
  169. long lErrx;
  170. int bHadError;
  171. int nPass;
  172. int nResult;
  173.  
  174.     puts("Disk R/W Through Rwabs()");
  175.     puts(VERSION);
  176.  
  177.     while((option=getopt(argc, argv, OPTIONS)) != EOF)
  178.         switch (toupper(option)) {
  179.         case 'B':  bDoGetBPB=1; break;
  180.         case 'E':  bAllErrors=1; break;
  181.         case 'F':  bFastRAM=1; break;
  182.         case 'Q':  bQuiet=1; break;
  183.         case 'Z':  bDoBufferFill=0; break;
  184.         case 'C':  nCount = GetNumArg(optarg); break;
  185.         case 'D':  nDevice = GetNumArg(optarg); break;
  186.         case 'I':  nIncrement = GetNumArg(optarg); break;
  187.         case 'L':  nLimit = GetNumArg(optarg); break;
  188.         case 'O':  nOffset = GetNumArg(optarg); break;
  189.         case 'P':  cSeed = (unsigned char)GetNumArg(optarg); break;
  190.         case 'R':  nRecord = nBaseRecord = GetNumArg(optarg); break;
  191.         case 'T':  nWritePause = GetNumArg(optarg); break;
  192.         case 'U':  nReadPause = GetNumArg(optarg); break;
  193.         default:   Usage(); exit(1);
  194.         }
  195.  
  196.     lBufferSize = (long)nCount*RECORDSIZE;
  197.  
  198.     if((pBuffer=(unsigned char *)Myalloc(3L*(lBufferSize+SLOP)+10L,
  199.         bFastRAM))==NULL){
  200.         printf("Unable to allocate transfer buffers\n");
  201.         exit(2);
  202.     }
  203.  
  204.     pBuf1 = pBuffer;
  205.     pBuf2 = pBuf1+lBufferSize+SLOP;
  206.     pBuf3 = pBuf2+lBufferSize+SLOP;
  207.  
  208. #ifdef VERBOSE
  209.     printf("Buffer size:  %08X\n", (long)lBufferSize);
  210.     printf("    Buffer1:  %08X\n", (long)pBuf1);
  211.     printf("    Buffer2:  %08X\n", (long)pBuf2);
  212.     printf("    Buffer3:  %08X\n", (long)pBuf3);
  213.     printf("     Offset:  %d\n", nOffset);
  214.     printf("     Device:  %d\n", nDevice);
  215.     printf("     Record:  %d\n", nRecord);
  216.     if (nLimit) {
  217.         printf("      Limit:  %d\n", nLimit);
  218.         if(nIncrement) printf("  Increment:  %d\n", nIncrement);
  219.         else printf("  Increment:  Random\n");
  220.     }
  221.     printf("      Count:  %d\n", nCount);
  222. #endif /* VERBOSE */
  223.  
  224.     printf("Are you SURE you want to trash media in TOS unit %d? ",
  225.         nDevice);
  226.     fflush(stdout);
  227.     gets((char *)pBuf1);
  228.  
  229.     if(toupper(*pBuf1) != 'Y') exit(1);
  230.  
  231.     if(bDoGetBPB) Getbpb(nDevice);        /* clear media change errors */
  232.  
  233.     nPass = 0;
  234.  
  235.     while(Cconis()==0){
  236.         ++nPass;
  237.         bHadError = 0;
  238.  
  239.         printf("\rCycle: %6d  Record: %6d Errors: %6ld  ",
  240.         nPass, nRecord, lErrors);
  241.         fflush(stdout);
  242.  
  243.         /* if any WritePause is specified, issue standby command */
  244.         if(nWritePause >= 0){
  245.         putchar('T');  fflush(stdout);
  246.         StandbyPause(nWritePause);
  247.         }
  248.  
  249.         /* write a known pattern to the disk */
  250.         SetBuffer(pBuf1, lBufferSize, nPass);
  251.         putchar('W');  fflush(stdout);
  252.         if(nResult=Rwabs(PHYSWRITE, pBuf1, nCount, nRecord, nDevice)){
  253.         printf("%02X", nResult);
  254.         ++lErrors;
  255.         bHadError = 1;
  256.         }
  257.  
  258.         /* now preset the destination buffers */
  259.         if(bDoBufferFill){
  260.         memset(pBuf2, cSeed, lBufferSize);
  261.         memset(pBuf3, cSeed, lBufferSize);
  262.         }
  263.  
  264.         /* read it in once */
  265.         if(nReadPause >= 0) {
  266.         putchar('U');  fflush(stdout);
  267.         StandbyPause(nReadPause);
  268.         }
  269.  
  270.         putchar('R');  fflush(stdout);
  271.         if(nResult=Rwabs(PHYSREAD, pBuf2, nCount, nRecord, nDevice)){
  272.         printf("%02X", nResult);
  273.         ++lErrors;
  274.         bHadError = 1;
  275.         }
  276.  
  277.         /* read it in a second time */
  278.         if(nReadPause >= 0) {
  279.         putchar('U');  fflush(stdout);
  280.         StandbyPause(nReadPause);
  281.         }
  282.  
  283.         putchar('S');  fflush(stdout);
  284.         if(nResult=Rwabs(PHYSREAD, pBuf3, nCount, nRecord, nDevice)){
  285.         printf("%02X", nResult);
  286.         ++lErrors;
  287.         bHadError = 1;
  288.         }
  289.  
  290.         /* now compare the two reads to the original */
  291.         putchar('C');  fflush(stdout);
  292.         bHadError += CompareBuffers(pBuf1, pBuf2, pBuf3, lBufferSize);
  293.  
  294.         if(bHadError) {
  295.         putchar('\n');
  296.         if(bQuiet==0) putchar('\007');
  297.         } else putchar('.');
  298.         fflush(stdout);
  299.  
  300.         /* set up a new starting record for the next cycle */
  301.         if(nLimit){        /* is the starting record allowed to change? */
  302.         if(nIncrement){    /* a linear increment */
  303.             if((nRecord += nIncrement) > (nBaseRecord+nLimit))
  304.             nRecord = nBaseRecord;
  305.         } else         /* a random distance up to limit away */
  306.             nRecord = nBaseRecord + (int)(Random()%(long)nLimit);
  307.         }
  308.     }
  309.  
  310.     (void)Cconin();        /* swallow up character */
  311. }
  312.